#include "Core/Plugin/PluginManager.h"
#include "Core/Network/INetworkPlugin.h"
#include "Core/Network/INetworkContext.h"
#include "Core/Network/ITCPSocket.h"
#include "Core/Network/ITCPServerSocket.h"
#include "Core/Profile/CodeProfile.h"
#include "NetworkTest.h"

const char * NetworkTest::GetName() const
{
	return "[NETWORK] Network Test";
}

Core::error NetworkTest::Create()
{
	if(Failed(UnitTest::Create()))
		return Core::errFailed;

	return Core::errOK;
}

Core::error NetworkTest::Destroy()
{
	if(Failed(UnitTest::Destroy()))
		return Core::errFailed;

	return Core::errOK;
}

Core::error NetworkTest::Execute()
{
	PROFILE(GetName());

	Core::Network::INetworkPlugin * pPlugin = Core::Plugin::PluginManager::GetInstance().RegisterPlugin<Core::Network::INetworkPlugin>(Core::Plugin::Network, "Network");
	if (pPlugin == NULL)
	{
		return Core::errFailed;
	}

	Core::Network::INetworkContext * pContext = pPlugin->CreateContext();
	Core::Network::ITCPSocket * pTCPSocket = pContext->CreateTCPSocket();

	pContext->DestroyTCPSocket(pTCPSocket);
	
	pPlugin->DestroyContext(pContext);

	Core::error e = Core::Plugin::PluginManager::GetInstance().UnregisterPlugin(Core::Plugin::Network);
	if (e != Core::errOK)
	{
		return Core::errFailed;
	}

	return Core::errOK;
}
